package winnu.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;


/**
 * This class was autogenerated by Torque on:
 *
 * [Thu Mar 25 06:20:49 CST 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to User
 */
@SuppressWarnings({ "unused", "serial" })
public abstract class BaseUser extends BaseObject
{
    /** The Peer class */
    private static final UserPeer peer =
        new UserPeer();

        
    /** The value for the userId field */
    private int userId;
      
    /** The value for the username field */
    private String username;
      
    /** The value for the password field */
    private String password;
      
    /** The value for the firstName field */
    private String firstName;
      
    /** The value for the middleName field */
    private String middleName;
      
    /** The value for the lastName field */
    private String lastName;
      
    /** The value for the position field */
    private String position;
      
    /** The value for the address field */
    private String address;
      
    /** The value for the contactNo field */
    private String contactNo;
      
    /** The value for the type field */
    private String type;
      
    /** The value for the deleted field */
    private boolean deleted;
  
    
    /**
     * Get the UserId
     *
     * @return int
     */
    public int getUserId()
    {
        return userId;
    }

                                              
    /**
     * Set the value of UserId
     *
     * @param v new value
     */
    public void setUserId(int v) throws TorqueException
    {
    
                  if (this.userId != v)
              {
            this.userId = v;
            setModified(true);
        }
    
          
                                  
        // update associated Sale
        if (collSales != null)
        {
            for (int i = 0; i < collSales.size(); i++)
            {
                ((Sale) collSales.get(i))
                    .setUserId(v);
            }
        }
                                          
        // update associated Item
        if (collItems != null)
        {
            for (int i = 0; i < collItems.size(); i++)
            {
                ((Item) collItems.get(i))
                    .setUserId(v);
            }
        }
                                          
        // update associated WithdrawnItem
        if (collWithdrawnItems != null)
        {
            for (int i = 0; i < collWithdrawnItems.size(); i++)
            {
                ((WithdrawnItem) collWithdrawnItems.get(i))
                    .setUserId(v);
            }
        }
                      }
  
    /**
     * Get the Username
     *
     * @return String
     */
    public String getUsername()
    {
        return username;
    }

                        
    /**
     * Set the value of Username
     *
     * @param v new value
     */
    public void setUsername(String v) 
    {
    
                  if (!ObjectUtils.equals(this.username, v))
              {
            this.username = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Password
     *
     * @return String
     */
    public String getPassword()
    {
        return password;
    }

                        
    /**
     * Set the value of Password
     *
     * @param v new value
     */
    public void setPassword(String v) 
    {
    
                  if (!ObjectUtils.equals(this.password, v))
              {
            this.password = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the FirstName
     *
     * @return String
     */
    public String getFirstName()
    {
        return firstName;
    }

                        
    /**
     * Set the value of FirstName
     *
     * @param v new value
     */
    public void setFirstName(String v) 
    {
    
                  if (!ObjectUtils.equals(this.firstName, v))
              {
            this.firstName = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the MiddleName
     *
     * @return String
     */
    public String getMiddleName()
    {
        return middleName;
    }

                        
    /**
     * Set the value of MiddleName
     *
     * @param v new value
     */
    public void setMiddleName(String v) 
    {
    
                  if (!ObjectUtils.equals(this.middleName, v))
              {
            this.middleName = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the LastName
     *
     * @return String
     */
    public String getLastName()
    {
        return lastName;
    }

                        
    /**
     * Set the value of LastName
     *
     * @param v new value
     */
    public void setLastName(String v) 
    {
    
                  if (!ObjectUtils.equals(this.lastName, v))
              {
            this.lastName = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Position
     *
     * @return String
     */
    public String getPosition()
    {
        return position;
    }

                        
    /**
     * Set the value of Position
     *
     * @param v new value
     */
    public void setPosition(String v) 
    {
    
                  if (!ObjectUtils.equals(this.position, v))
              {
            this.position = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Address
     *
     * @return String
     */
    public String getAddress()
    {
        return address;
    }

                        
    /**
     * Set the value of Address
     *
     * @param v new value
     */
    public void setAddress(String v) 
    {
    
                  if (!ObjectUtils.equals(this.address, v))
              {
            this.address = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the ContactNo
     *
     * @return String
     */
    public String getContactNo()
    {
        return contactNo;
    }

                        
    /**
     * Set the value of ContactNo
     *
     * @param v new value
     */
    public void setContactNo(String v) 
    {
    
                  if (!ObjectUtils.equals(this.contactNo, v))
              {
            this.contactNo = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Type
     *
     * @return String
     */
    public String getType()
    {
        return type;
    }

                        
    /**
     * Set the value of Type
     *
     * @param v new value
     */
    public void setType(String v) 
    {
    
                  if (!ObjectUtils.equals(this.type, v))
              {
            this.type = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Deleted
     *
     * @return boolean
     */
    public boolean getDeleted()
    {
        return deleted;
    }

                        
    /**
     * Set the value of Deleted
     *
     * @param v new value
     */
    public void setDeleted(boolean v) 
    {
    
                  if (this.deleted != v)
              {
            this.deleted = v;
            setModified(true);
        }
    
          
              }
  
         
                                
            
    /**
     * Collection to store aggregation of collSales
     */
    @SuppressWarnings("unchecked")
	protected List collSales;

    /**
     * Temporary storage of collSales to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    @SuppressWarnings("unchecked")
	protected void initSales()
    {
        if (collSales == null)
        {
            collSales = new ArrayList();
        }
    }

    /**
     * Method called to associate a Sale object to this object
     * through the Sale foreign key attribute
     *
     * @param l Sale
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public void addSale(Sale l) throws TorqueException
    {
        getSales().add(l);
        l.setUser((User) this);
    }

    /**
     * The criteria used to select the current contents of collSales
     */
    private Criteria lastSalesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSales(new Criteria())
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getSales() throws TorqueException
    {
        if (collSales == null)
        {
            collSales = getSales(new Criteria(10));
        }
        return collSales;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related Sales from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getSales(Criteria criteria) throws TorqueException
    {
        if (collSales == null)
        {
            if (isNew())
            {
               collSales = new ArrayList();
            }
            else
            {
                      criteria.add(SalePeer.USERID, getUserId() );
                      collSales = SalePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(SalePeer.USERID, getUserId());
                      if (!lastSalesCriteria.equals(criteria))
                {
                    collSales = SalePeer.doSelect(criteria);
                }
            }
        }
        lastSalesCriteria = criteria;

        return collSales;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSales(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getSales(Connection con) throws TorqueException
    {
        if (collSales == null)
        {
            collSales = getSales(new Criteria(10), con);
        }
        return collSales;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related Sales from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getSales(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSales == null)
        {
            if (isNew())
            {
               collSales = new ArrayList();
            }
            else
            {
                       criteria.add(SalePeer.USERID, getUserId());
                       collSales = SalePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(SalePeer.USERID, getUserId());
                       if (!lastSalesCriteria.equals(criteria))
                 {
                     collSales = SalePeer.doSelect(criteria, con);
                 }
             }
         }
         lastSalesCriteria = criteria;

         return collSales;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related Sales from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getSalesJoinUser(Criteria criteria)
        throws TorqueException
    {
        if (collSales == null)
        {
            if (isNew())
            {
               collSales = new ArrayList();
            }
            else
            {
                            criteria.add(SalePeer.USERID, getUserId());
                            collSales = SalePeer.doSelectJoinUser(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SalePeer.USERID, getUserId());
                        if (!lastSalesCriteria.equals(criteria))
            {
                collSales = SalePeer.doSelectJoinUser(criteria);
            }
        }
        lastSalesCriteria = criteria;

        return collSales;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collItems
     */
    @SuppressWarnings("unchecked")
	protected List collItems;

    /**
     * Temporary storage of collItems to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    @SuppressWarnings("unchecked")
	protected void initItems()
    {
        if (collItems == null)
        {
            collItems = new ArrayList();
        }
    }

    /**
     * Method called to associate a Item object to this object
     * through the Item foreign key attribute
     *
     * @param l Item
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public void addItem(Item l) throws TorqueException
    {
        getItems().add(l);
        l.setUser((User) this);
    }

    /**
     * The criteria used to select the current contents of collItems
     */
    private Criteria lastItemsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getItems(new Criteria())
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getItems() throws TorqueException
    {
        if (collItems == null)
        {
            collItems = getItems(new Criteria(10));
        }
        return collItems;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related Items from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getItems(Criteria criteria) throws TorqueException
    {
        if (collItems == null)
        {
            if (isNew())
            {
               collItems = new ArrayList();
            }
            else
            {
                      criteria.add(ItemPeer.USERID, getUserId() );
                      collItems = ItemPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(ItemPeer.USERID, getUserId());
                      if (!lastItemsCriteria.equals(criteria))
                {
                    collItems = ItemPeer.doSelect(criteria);
                }
            }
        }
        lastItemsCriteria = criteria;

        return collItems;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getItems(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getItems(Connection con) throws TorqueException
    {
        if (collItems == null)
        {
            collItems = getItems(new Criteria(10), con);
        }
        return collItems;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related Items from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getItems(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collItems == null)
        {
            if (isNew())
            {
               collItems = new ArrayList();
            }
            else
            {
                       criteria.add(ItemPeer.USERID, getUserId());
                       collItems = ItemPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(ItemPeer.USERID, getUserId());
                       if (!lastItemsCriteria.equals(criteria))
                 {
                     collItems = ItemPeer.doSelect(criteria, con);
                 }
             }
         }
         lastItemsCriteria = criteria;

         return collItems;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related Items from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getItemsJoinUser(Criteria criteria)
        throws TorqueException
    {
        if (collItems == null)
        {
            if (isNew())
            {
               collItems = new ArrayList();
            }
            else
            {
                            criteria.add(ItemPeer.USERID, getUserId());
                            collItems = ItemPeer.doSelectJoinUser(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(ItemPeer.USERID, getUserId());
                        if (!lastItemsCriteria.equals(criteria))
            {
                collItems = ItemPeer.doSelectJoinUser(criteria);
            }
        }
        lastItemsCriteria = criteria;

        return collItems;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collWithdrawnItems
     */
    @SuppressWarnings("unchecked")
	protected List collWithdrawnItems;

    /**
     * Temporary storage of collWithdrawnItems to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    @SuppressWarnings("unchecked")
	protected void initWithdrawnItems()
    {
        if (collWithdrawnItems == null)
        {
            collWithdrawnItems = new ArrayList();
        }
    }

    /**
     * Method called to associate a WithdrawnItem object to this object
     * through the WithdrawnItem foreign key attribute
     *
     * @param l WithdrawnItem
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public void addWithdrawnItem(WithdrawnItem l) throws TorqueException
    {
        getWithdrawnItems().add(l);
        l.setUser((User) this);
    }

    /**
     * The criteria used to select the current contents of collWithdrawnItems
     */
    private Criteria lastWithdrawnItemsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getWithdrawnItems(new Criteria())
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getWithdrawnItems() throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            collWithdrawnItems = getWithdrawnItems(new Criteria(10));
        }
        return collWithdrawnItems;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    @SuppressWarnings("unchecked")
	public List getWithdrawnItems(Criteria criteria) throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                      criteria.add(WithdrawnItemPeer.USERID, getUserId() );
                      collWithdrawnItems = WithdrawnItemPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(WithdrawnItemPeer.USERID, getUserId());
                      if (!lastWithdrawnItemsCriteria.equals(criteria))
                {
                    collWithdrawnItems = WithdrawnItemPeer.doSelect(criteria);
                }
            }
        }
        lastWithdrawnItemsCriteria = criteria;

        return collWithdrawnItems;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getWithdrawnItems(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getWithdrawnItems(Connection con) throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            collWithdrawnItems = getWithdrawnItems(new Criteria(10), con);
        }
        return collWithdrawnItems;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     * If this User is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    @SuppressWarnings("unchecked")
	public List getWithdrawnItems(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                       criteria.add(WithdrawnItemPeer.USERID, getUserId());
                       collWithdrawnItems = WithdrawnItemPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(WithdrawnItemPeer.USERID, getUserId());
                       if (!lastWithdrawnItemsCriteria.equals(criteria))
                 {
                     collWithdrawnItems = WithdrawnItemPeer.doSelect(criteria, con);
                 }
             }
         }
         lastWithdrawnItemsCriteria = criteria;

         return collWithdrawnItems;
     }

                                    
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getWithdrawnItemsJoinDoctor(Criteria criteria)
        throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                            criteria.add(WithdrawnItemPeer.USERID, getUserId());
                            collWithdrawnItems = WithdrawnItemPeer.doSelectJoinDoctor(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(WithdrawnItemPeer.USERID, getUserId());
                        if (!lastWithdrawnItemsCriteria.equals(criteria))
            {
                collWithdrawnItems = WithdrawnItemPeer.doSelectJoinDoctor(criteria);
            }
        }
        lastWithdrawnItemsCriteria = criteria;

        return collWithdrawnItems;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getWithdrawnItemsJoinSale(Criteria criteria)
        throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                            criteria.add(WithdrawnItemPeer.USERID, getUserId());
                            collWithdrawnItems = WithdrawnItemPeer.doSelectJoinSale(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(WithdrawnItemPeer.USERID, getUserId());
                        if (!lastWithdrawnItemsCriteria.equals(criteria))
            {
                collWithdrawnItems = WithdrawnItemPeer.doSelectJoinSale(criteria);
            }
        }
        lastWithdrawnItemsCriteria = criteria;

        return collWithdrawnItems;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getWithdrawnItemsJoinItemBatch(Criteria criteria)
        throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                            criteria.add(WithdrawnItemPeer.USERID, getUserId());
                            collWithdrawnItems = WithdrawnItemPeer.doSelectJoinItemBatch(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(WithdrawnItemPeer.USERID, getUserId());
                        if (!lastWithdrawnItemsCriteria.equals(criteria))
            {
                collWithdrawnItems = WithdrawnItemPeer.doSelectJoinItemBatch(criteria);
            }
        }
        lastWithdrawnItemsCriteria = criteria;

        return collWithdrawnItems;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this User is new, it will return
     * an empty collection; or if this User has previously
     * been saved, it will retrieve related WithdrawnItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in User.
     */
    @SuppressWarnings("unchecked")
	protected List getWithdrawnItemsJoinUser(Criteria criteria)
        throws TorqueException
    {
        if (collWithdrawnItems == null)
        {
            if (isNew())
            {
               collWithdrawnItems = new ArrayList();
            }
            else
            {
                            criteria.add(WithdrawnItemPeer.USERID, getUserId());
                            collWithdrawnItems = WithdrawnItemPeer.doSelectJoinUser(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(WithdrawnItemPeer.USERID, getUserId());
                        if (!lastWithdrawnItemsCriteria.equals(criteria))
            {
                collWithdrawnItems = WithdrawnItemPeer.doSelectJoinUser(criteria);
            }
        }
        lastWithdrawnItemsCriteria = criteria;

        return collWithdrawnItems;
    }
                            


          
    @SuppressWarnings("unchecked")
	private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    @SuppressWarnings("unchecked")
	public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("UserId");
              fieldNames.add("Username");
              fieldNames.add("Password");
              fieldNames.add("FirstName");
              fieldNames.add("MiddleName");
              fieldNames.add("LastName");
              fieldNames.add("Position");
              fieldNames.add("Address");
              fieldNames.add("ContactNo");
              fieldNames.add("Type");
              fieldNames.add("Deleted");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("UserId"))
        {
                return new Integer(getUserId());
            }
          if (name.equals("Username"))
        {
                return getUsername();
            }
          if (name.equals("Password"))
        {
                return getPassword();
            }
          if (name.equals("FirstName"))
        {
                return getFirstName();
            }
          if (name.equals("MiddleName"))
        {
                return getMiddleName();
            }
          if (name.equals("LastName"))
        {
                return getLastName();
            }
          if (name.equals("Position"))
        {
                return getPosition();
            }
          if (name.equals("Address"))
        {
                return getAddress();
            }
          if (name.equals("ContactNo"))
        {
                return getContactNo();
            }
          if (name.equals("Type"))
        {
                return getType();
            }
          if (name.equals("Deleted"))
        {
                return new Boolean(getDeleted());
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(UserPeer.USERID))
        {
                return new Integer(getUserId());
            }
          if (name.equals(UserPeer.USERNAME))
        {
                return getUsername();
            }
          if (name.equals(UserPeer.PASSWORD))
        {
                return getPassword();
            }
          if (name.equals(UserPeer.FIRSTNAME))
        {
                return getFirstName();
            }
          if (name.equals(UserPeer.MIDDLENAME))
        {
                return getMiddleName();
            }
          if (name.equals(UserPeer.LASTNAME))
        {
                return getLastName();
            }
          if (name.equals(UserPeer.POSITION))
        {
                return getPosition();
            }
          if (name.equals(UserPeer.ADDRESS))
        {
                return getAddress();
            }
          if (name.equals(UserPeer.CONTACTNO))
        {
                return getContactNo();
            }
          if (name.equals(UserPeer.TYPE))
        {
                return getType();
            }
          if (name.equals(UserPeer.DELETED))
        {
                return new Boolean(getDeleted());
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getUserId());
            }
              if (pos == 1)
        {
                return getUsername();
            }
              if (pos == 2)
        {
                return getPassword();
            }
              if (pos == 3)
        {
                return getFirstName();
            }
              if (pos == 4)
        {
                return getMiddleName();
            }
              if (pos == 5)
        {
                return getLastName();
            }
              if (pos == 6)
        {
                return getPosition();
            }
              if (pos == 7)
        {
                return getAddress();
            }
              if (pos == 8)
        {
                return getContactNo();
            }
              if (pos == 9)
        {
                return getType();
            }
              if (pos == 10)
        {
                return new Boolean(getDeleted());
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(UserPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    UserPeer.doInsert((User) this, con);
                    setNew(false);
                }
                else
                {
                    UserPeer.doUpdate((User) this, con);
                }
            }

                                      
                
            if (collSales != null)
            {
                for (int i = 0; i < collSales.size(); i++)
                {
                    ((Sale) collSales.get(i)).save(con);
                }
            }
                                          
                
            if (collItems != null)
            {
                for (int i = 0; i < collItems.size(); i++)
                {
                    ((Item) collItems.get(i)).save(con);
                }
            }
                                          
                
            if (collWithdrawnItems != null)
            {
                for (int i = 0; i < collWithdrawnItems.size(); i++)
                {
                    ((WithdrawnItem) collWithdrawnItems.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  userId ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setUserId(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setUserId(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getUserId());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public User copy() throws TorqueException
    {
        return copyInto(new User());
    }
  
    @SuppressWarnings("unchecked")
	protected User copyInto(User copyObj) throws TorqueException
    {
          copyObj.setUserId(userId);
          copyObj.setUsername(username);
          copyObj.setPassword(password);
          copyObj.setFirstName(firstName);
          copyObj.setMiddleName(middleName);
          copyObj.setLastName(lastName);
          copyObj.setPosition(position);
          copyObj.setAddress(address);
          copyObj.setContactNo(contactNo);
          copyObj.setType(type);
          copyObj.setDeleted(deleted);
  
                    copyObj.setUserId(0);
                                                                        
                                      
                
        List v = getSales();
        for (int i = 0; i < v.size(); i++)
        {
            Sale obj = (Sale) v.get(i);
            copyObj.addSale(obj.copy());
        }
                                                  
                
        v = getItems();
        for (int i = 0; i < v.size(); i++)
        {
            Item obj = (Item) v.get(i);
            copyObj.addItem(obj.copy());
        }
                                                  
                
        v = getWithdrawnItems();
        for (int i = 0; i < v.size(); i++)
        {
            WithdrawnItem obj = (WithdrawnItem) v.get(i);
            copyObj.addWithdrawnItem(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public UserPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("User:\n");
        str.append("UserId = ")
           .append(getUserId())
           .append("\n");
        str.append("Username = ")
           .append(getUsername())
           .append("\n");
        str.append("Password = ")
           .append(getPassword())
           .append("\n");
        str.append("FirstName = ")
           .append(getFirstName())
           .append("\n");
        str.append("MiddleName = ")
           .append(getMiddleName())
           .append("\n");
        str.append("LastName = ")
           .append(getLastName())
           .append("\n");
        str.append("Position = ")
           .append(getPosition())
           .append("\n");
        str.append("Address = ")
           .append(getAddress())
           .append("\n");
        str.append("ContactNo = ")
           .append(getContactNo())
           .append("\n");
        str.append("Type = ")
           .append(getType())
           .append("\n");
        str.append("Deleted = ")
           .append(getDeleted())
           .append("\n");
        return(str.toString());
    }
}
